﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using _3Dsoundor2Dgraphor.Sound;

namespace _3Dsoundor2Dgraphor.Graphics
{
	class Player : Element
	{
		public int size;

		public SoundSink soundSink;

		public Player(int startX, int startY, int _size)
		{
			_position.X = startX;
			_position.Y = startY;
			_orjentation.X = 0;
			_orjentation.Y = 1;
			size = _size;
			mBrush = new SolidBrush(Color.Green);

			soundSink = new SoundSink();
		}

		public override void draw(System.Drawing.Graphics output)
		{
			output.FillRectangle(mBrush, _position.X, _position.Y, size, size);
			updateSoundSinkPos();
		}

		public override void action(PointF point)
		{
			throw new NotImplementedException();
		}

		public void move(int X, int Y)
		{
			_position.X += X;
			_position.Y += Y;
			if (_position.X <= sceneX + sceneW - (size / 2) && _position.Y <= sceneY + sceneH - (size / 2) && _position.X >= sceneX + (size / 2) && _position.Y >= sceneY + (size / 2))
			{
				return;
			}
			else
			{
				if (_position.X >= sceneX + sceneW - (size/2))
				{
					_position.X = sceneX + sceneW - (size/2);
				}
				if (_position.Y >= sceneY + sceneH - (size / 2))
				{
					_position.Y = sceneY + sceneH - (size/2);
				}
				if (_position.X <= sceneX + (size / 2))
				{
					_position.X = sceneX + (size / 2);
				}
				if (_position.Y <= sceneY + (size / 2))
				{
					_position.Y = sceneY + (size / 2);
				}
				return;
			}
		}
		public void updateSoundSinkPos()
		{
			if (SoundBase.system != null) soundSink.update(_position, _orjentation);
		}
	}
}
